#pragma comment(linker, "/STACK:10000000")
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <set>
#include <map>
#include <cstdio>
#include <cassert>
#include <string>
#include <cstring>
#define ldb long double
#define ll long long
#define fi first
#define se second
#define fill(a, c) memset(a, c, sizeof(a))
#define sqr(a) ((a) * (a))
#define nextLine() {int c = 0; while((c = getchar()) != 10 && c != EOF);}
#define getBit(mask, k) (((mask) / pw[k]) % pw[1])
#define setBit(mask, k, l) (((mask) / pw[k + 1] * pw[1] + (l)) * pw[k] + ((mask) % pw[k]))
#define debug(a) cerr << #a << " = " << a << " ";
#define debugl(a) cerr << #a << " = " << a << "\n";
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a)
#define ff first
#define ss second 
const ldb LDINF = 9128739847123.00;
const ldb eps = 1e-9;
const ll inf = 9000000000000000000ll;
const ldb pi = fabsl(atan2l(0.0, -1.0));
using namespace std;
int n, m, k;
ll dp[52][52][110];
ll p[52][52][110];
vector <pair <int, pair <ll, pair <ll, int> > > > task;

void load()
{
	cin >> n >> m >> k;
	ll a, b;
	int c;
	for (int i = 0; i < m; i++)
	{
		scanf("%I64d%I64d%d", &a, &b, &c);
		task.pb(mp(c, mp(a, mp(b, i))));
   	}
   	sort(task.begin(), task.end());
}  	

ll f(int i, int j, int t)
{
	if (i == n)
		return 0;
	if (dp[i][j][t] != -1) return dp[i][j][t];
	dp[i][j][t] = -inf;
	ll cur = task[j].ss.ff + t;
	for (int l = j + 1; l < task.size(); l++)
	{
		if (task[j].ff < task[l].ff)
		{
			 if (task[l].ss.ff <= cur + k && cur + k <= task[l].ss.ss.ff)
			 {
			 	if (dp[i][j][t] < f(i + 1, l, cur + k - task[l].ss.ff) + cur + k)
			 	{
			 		dp[i][j][t] = f(i + 1, l, cur + k - task[l].ss.ff) + cur + k;
			 		p[i][j][t] = (l << 1);
			 	}
			 }
			 if (task[l].ss.ff <= cur * k && cur * k <= task[l].ss.ss.ff)
			 {
			 	if (dp[i][j][t] < f(i + 1, l, cur * k - task[l].ss.ff) + cur * k)
			 	{
			 		dp[i][j][t] = f(i + 1, l, cur * k - task[l].ss.ff) + cur * k;
			 		p[i][j][t] = (l << 1) | 1;
			 	}
			 }
		}
	}
//	cerr << i << " " << j << " " << t << " == " << dp[i][j][t] << "\n";
	return dp[i][j][t];
}	


void solve()
{
	//reverse(task.begin(), task.end());
	memset(dp, -1, sizeof dp);
	ll res = -inf;
	int pi, pj;
	for (int i = 0; i < task.size(); i++)
	{
	//	cerr << task[i].ff << " " << task[i].ss.ff << " " << task[i].ss.ss.ff << " " << task[i].ss.ss.ss << "\n";
		for (int j = 0; j < task[i].ss.ss.ff - task[i].ss.ff + 1; j++)
		{
			if (res < f(1, i, j) + task[i].ss.ff + j)
			{
				res = f(1, i, j) + task[i].ss.ff + j;
				pi = i;
				pj = j;
			}
		}
	}
	if (res < 0)
	{
		cout << "NO";
		return ;
	}
	cout << "YES\n";
	for (int i = 1; i <= n; i++)
	{	
		cout << task[pi].ss.ss.ss + 1 << " " << task[pi].ss.ff + pj << "\n";
		if (p[i][pi][pj] % 2 == 0)
		{
			int l = p[i][pi][pj] / 2;
			pj = task[pi].ss.ff + pj + k - task[l].ss.ff;
			pi = l;
		}
		else
		{
			int l = p[i][pi][pj] / 2;
			pj = (task[pi].ss.ff + pj) * k - task[l].ss.ff;
			pi = l;
		}
	}

}

#define file "c"
int main()
{
	#ifndef ONLINE_JUDGE
		freopen(file".in", "rt", stdin);
		freopen(file".out", "wt", stdout);
	#endif
	load();
	solve();
	return 0;
}
